<?php


class imagegallery_image {
	function form($object) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();
		
		$form = new form();
		if (!isset($object->id)) {
			$form->meta('parent',$object->gallery_id);
			$object->name = '';
			$object->alt = '';
			$object->description = '';
			$object->newwindow = 1;
		} else {
			$form->meta('id',$object->id);
		}
		
		$form->register('name','Name',new textcontrol($object->name));
		$form->register('alt','Alt Tag',new textcontrol($object->alt));
		
		global $db;
		$imagenames = array();
		if (!isset($object->rank) || $object->rank != 0) $imagenames[0] = 'At the Beginning';
		foreach ($db->selectObjects('imagegallery_image','gallery_id='.$object->gallery_id . ' ORDER BY rank ASC') as $i) {
			if ($object->rank == $i->rank) $imagenames[$i->rank+1] = '------------';
			else if ($object->rank != $i->rank+1) $imagenames[$i->rank+1] = 'After "' . $i->name . '"';
		}
		if (!isset($object->id)) $object->rank = count($imagenames)-1;
		
		$form->register('rank','Place Image',new dropdowncontrol($object->rank+1,$imagenames));
		$form->register('description','Description',new htmleditorcontrol($object->description));
		$form->register('newwindow','Open in New Window',new checkboxcontrol($object->newwindow,true));
		$form->register('file_id','Image',new ajax_select_file("file_id",0,$object->file_id,true));
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}
	
	function update($values,$object) {
		$object->name = $values['name'];
		$object->alt = $values['alt'];
		$object->file_id= intval($values['file_id']);
		$object->description = $values['description'];
		$object->newwindow = (isset($values['newwindow']) ? 1 : 0);
		return $object;
	}
}

?>
